<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" id="uname" name="username">姓名
<br>
<input type="text" id="age" name="agee"> 年龄
<br>
<input type="submit" id="mybtn">
<br>
<span class="iii">hahhahaha</span>

<script>
    let btn = document.querySelector("#mybtn");
    btn.addEventListener("click", () => {
        let xhr = new XMLHttpRequest();
        xhr.onreadystatechange = () => {
            if (xhr.readyState == 4 && xhr.status == 200) {
                let spanElement = document.querySelector(".iii");
                spanElement.innerHTML = xhr.responseText;
            }
        }
        xhr.open("post", "ajaxrequest", true);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

        let value = document.getElementById("uname").value;
        let age = document.getElementById("age").value;
        xhr.send("username="+value+"&age="+age);
    }
    )


</script>

</body>
</html>
